﻿using System;
using System.Windows.Forms;

namespace PMngr.Main
{
    public interface IControl
    {
        void InitializeControls();
    }

    public partial class BaseControl : UserControl, IControl
    {
        public LoggingWriter LogWriter = delegate { };

        public BaseControl()
        {
            InitializeComponent();
        }

        public virtual void InitializeControls()
        { }

        // loging
        internal protected void LogTrace(string message)
        {
            LogTrace(message, MessageType.Information);
        }

        internal protected void LogTrace(string message, MessageType messageType)
        {
            var icon = (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), messageType.ToString());
            LogTrace(message, icon);
        }

        private void LogTrace(string message, MessageBoxIcon icon)
        {
            LogWriter(message);
            MessageFactory.Show(message, icon);
        }
        // yes or no
        internal protected DialogResult MessageBoxShow(string message)
        {
            return MessageFactory.MessageBoxShow(message);
        }

    }

    public delegate void LoggingWriter(string message);

    public enum MessageType
    {
        Error,
        Exclamation,
        Information,
        Warning,
        Question
    }

}
